// app/model/article.js
module.exports = app => {
    const mongoose = app.mongoose;
    const Schema = mongoose.Schema;
  
    const ArticleSchema = new Schema({
      title: {
        type: String,
        required: true
      },
      slug: { 
        type: String, 
        unique: true, 
        required: true 
      },
      description: {
        type: String,
        required: true
      },
      body: {
        type: String,
        required: true
      },
      author: {
        type: Schema.Types.ObjectId,
        ref: 'User',
        required: true
      },
      tagList: [{type: String}],
      createdAt: {
        type: Date,
        default: Date.now
      },
      updatedAt: {
        type: Date,
        default: Date.now
      },
      favoritesCount: {
        type: Number,
        default: 0
      }
    });
  
    return mongoose.model('Article', ArticleSchema);
  }